package org.yang.novel.wx.service.impl;

import static org.yang.common.Msg.*;

import org.yang.common.Msg;
import org.yang.novel.wx.dao.TypeMapper;
import org.yang.novel.wx.entity.Type;
import org.yang.novel.wx.service.TypeService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

/**
 * 分类服务实现
 * @author shichenyang
 * @email gyv12345@163.com
 * @date 2019/01/07
 */
@Service
@Transactional(rollbackFor = Exception.class)
public class TypeServiceImpl implements TypeService {
    @Resource
    private TypeMapper typeMapper;

    @Override
    public Msg addType(Type type) {
        int i=  typeMapper.insert(type);
        return i>0?ok(ADD_SUCCESS):err(ADD_ERR);
    }

    @Override
    public Msg updateType(Type type) {
        int i= typeMapper.updateByParam(type);
        return i>0?ok(UPDATE_SUCCESS):err(UPDATE_ERR);
    }

    @Override
    public Msg delType(Type type) {
        int i=typeMapper.del(type.getId());
        return i>0?ok(DEL_SUCCESS):err(DEL_ERR);
    }

    @Override
    public PageInfo getTypes(Type type, Integer page, Integer limit) {
        PageHelper.startPage(page,limit);
        List<Type> types=typeMapper.list(type);
        PageInfo pi=new PageInfo(types);
        return pi;
    }
}
